const mongoose = require('mongoose');

const ProblemSchema = new mongoose.Schema({
  title:{
    type: String,
    unique: true
  },
  url: String,
  type: String,
  updatedAt: {
    type: Date,
    default: () => Date.now()
  },
}, { collection: 'problemPool' })

ProblemSchema.statics.findByType = async function (type) {
  const result = await this.find({ type:type.toUpperCase() });
  if (result) {
    
    // console.log(result);
    return result;
  }else {
    // throw new Error("no record found")
   
  }

}

module.exports = mongoose.model('problemPool', ProblemSchema);